$(document).ready(function() {
	//点击退出登录跳转至登录界面
	mui('body').on("tap", ".signOut", function() {
		//清除"token"缓存并跳转至登录页面
		localStorage.setItem("token", "");
		plus.runtime.restart();
	})

	//获取APP版本号，然后进行数据渲染
	mui.getJSON("../manifest.json", null, function(data) {
		var system = "";
		var v = data.version.name;
		ismobile(1) == 1 ? system = "Android" : system = "IOS";
		require(weburl + checkupdates, "json", "post", {
			token: localStorage.getItem("token"),
			version: v,
			system: system
		}, function(response) {
			console.log(JSON.stringify(response));
			if(compareVersion(v, response.data.version)) {
				$(".version").attr("data-sign", "true");
				$(".version").find(".zi").html("<span class='xin'></span>有版本更新");
				mui("body").on("tap", ".version", function() {
					if($(this).attr("data-sign") == "true") {
						mui.confirm("有版本更新，是否需要更新？", " ", ["立即更新", "稍后更新"], function(e) {
							if(e.index == 0) {
								if(plus.os.name == "Android") {
									var wt = plus.nativeUI.showWaiting('下载更新中，请勿关闭');
									//下载安装包函数
									var dtask = plus.downloader.createDownload(response.data.url, {}, function(d, status) {
										if(status == 200) { // 下载成功   
											//关闭等待提示框
											//调用手机安装功能
											mui.confirm("下载完成，如未自动安装请手动进行安装！", "", "关闭", function() {});
											plus.nativeUI.closeWaiting();
											var path = d.filename;
											plus.runtime.install(path);
										} else { //下载失败   
											plus.nativeUI.closeWaiting();
											alert("下载失败，请前往应用市场下载");
										}
									});
									dtask.start();
								} else if(plus.os.name == "iOS") {
									plus.runtime.openURL('https://itunes.apple.com/cn/app/%E5%A4%A9%E6%8B%A9%E5%8F%AF%E4%BB%98/id1278210839?mt=8')
								}
							} else {
								console.log(e.index);
							}
						}, "div");
					} else {

					}
				})
			} else {
				$(".version").attr("data-sign", "false");
				$(".version").find(".zi").html(v);
			}
		}, function() {
			//异常处理；
			$(".version").attr("data-sign", "false");
			$(".version").find(".zi").html(v);
		})

	})
	//点击修改支付密码
	mui("body").on("tap", ".modifyPay", function() {
		mui.openWindow("../view/payPassword.html", "payPassword");
	})
	//点击更新说明
	mui("body").on("tap", ".update", function() {
		mui.openWindow("../view/updata.html", "updata");
	})
	//点击扫码通道
	mui("body").on("tap", ".code_pass", function() {
		mui.openWindow("../view/code_pass.html", "code_pass");
	})

	//点击修改登录密码
	mui("body").on("tap", ".login_pas", function() {
		mui.openWindow("updateLoginPass.html", "updateLoginPass");
	})
})